/*
 * @Author: li 2696915640@qq.com
 * @Date: 2023-06-30 16:49:16
 * @LastEditors: li 2696915640@qq.com
 * @LastEditTime: 2023-07-18 17:09:51
 * @FilePath: \newpig\src\components\utils\requect.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import axios from "axios";
axios.defaults.withCredentials = true;  //前后端分离session使用
import Vue from "vue";
import { Message } from "element-ui";
Vue.prototype.$message = Message;
//const G = window.g // 在static/js/config.js中可以动态的修改后台请求地址
const instance = axios.create({
  // baseURL: "http://localhost:8080/",
  baseURL: "http://101.201.81.51:4434/",
  timeout: 60000
});
// console.log(process.env.VUE_APP_API_URL);
// Add a request interceptor
instance.interceptors.request.use(
  function(config) {
    // Do something before request is sent
    return config;
  },
  function(error) {
    // Do something with request error
    return Promise.reject(error);
  }
);

// Add a response interceptor
instance.interceptors.response.use(function (response) {
  // Do something with response data
  // console.log(response.data);
    if (response.data.code != 200) {
      console.log("response.data.message:", response.data.message);
    if (response.data.message == undefined) {
        console.log("excelExport...");
    }
    else if(response.data.message!=null)
      Vue.prototype.$message.warning(response.data.message);
    else
      Vue.prototype.$message.error("服务器异常");
  }
    return response;
  },
  function(error) {
    // Do something with response error
    return Promise.reject(error);
  }
);

export default instance;
